﻿
using System;
using System.Collections.Generic;
using System.Text;

namespace HttpClient
{
	public class ContentConfiguration<T>
		where T : class
	{
		T src;
		HttpRequest request;
	    private HeaderConfiguration<T> headers;

        public ContentConfiguration(HttpRequest request, T src, HeaderConfiguration<T> headers)
		{
			this.src = src;
			this.request = request;
            this.headers = headers;
		}

        public ContentConfiguration<T> Parameter(String name, String value)
		{
			request.contentParameters.Add(name, value);
			return this;
		}

        public ContentConfiguration<T> Parameters(Dictionary<String, String> parameters)
		{
        	foreach (var param in parameters)
        	{
				request.contentParameters.Add(param.Key, param.Value);
        	}
			return this;
		}

        public ContentConfiguration<T> Xml(String content)
		{
            headers.ContentType("application/xml");
            request.content = Encoding.UTF8.GetBytes(content);
			return this;
		}

        public ContentConfiguration<T> Json(String jsonContent)
        {
            headers.ContentType("application/json");
            request.content = Encoding.UTF8.GetBytes(jsonContent);
			return this;
		}
		
		public T And { get { return src; } }
	}
}
